package com.huangfu.easysardine.admin.rest;

import com.github.pagehelper.PageHelper;
import com.huangfu.easysardine.admin.biz.GroupTypeBiz;
import com.huangfu.easysardine.admin.entity.GroupType;
import com.huangfu.easysardine.common.msg.TableResultResponse;
import com.huangfu.easysardine.common.rest.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

/**
 * Created with IntelliJ IDEA.
 * User: huangfu.daohui
 * Date: 2017-8-14
 * Time: 13:32
 * Description:用户组类型
 */
@Controller
@RequestMapping("groupType")
public class GroupTypeController extends BaseController<GroupTypeBiz, GroupType> {

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    public TableResultResponse<GroupType> page(int limit, int offset, String name) {
        Example example = new Example(GroupType.class);
        if (StringUtils.isNotBlank(name))
            example.createCriteria().andLike("name", "%" + name + "%");
        int count = baseBiz.selectCountByExample(example);
        PageHelper.startPage(offset, limit);
        return new TableResultResponse<GroupType>(count, baseBiz.selectByExample(example));
    }

}
